package com.neusoft.modules.web.controller;


import com.neusoft.common.utils.R;
import com.neusoft.modules.web.entity.DeviceEntity;
import com.neusoft.modules.web.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 设备信息
 */
@RestController
@RequestMapping("/device")
public class DeviceController {

	@Autowired
	private DeviceService deviceService;

	/**
	 * 所有设备信息
	 */
	@GetMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		List<DeviceEntity> list = deviceService.queryAllDevices();
		return R.ok().put("list", list);
	}

	
	/**
	 * 设备信息
	 */
	@GetMapping("/info/{id}")
	public R info(@PathVariable("id") Long id){
		DeviceEntity device = deviceService.queryDeviceById(id);
		return R.ok().put("device", device);
	}
	
	/**
	 * 保存设备信息
	 */
	@PostMapping("/save")
	public R save(@RequestBody DeviceEntity device){
		deviceService.saveDevice(device);
		return R.ok();
	}
	
	/**
	 * 修改设备信息
	 */
	@PostMapping("/update")
	public R update(@RequestBody DeviceEntity device){
		deviceService.updateDevice(device);
		return R.ok();
	}
	
	/**
	 * 删除设备信息
	 */
	@GetMapping("/delete/{id}")
	public R delete(@PathVariable Long id){
		deviceService.deleteDevice(id);
		return R.ok();
	}
}
